$(function () {
	/**
	 * [时间取年-月]
	 */
	template.defaults.imports.dateSplit = function(value, length) {
		if (value != 'string') {
			value += ""
		}
		if(length == 0) {
			return value.split('-')[length]
		}else {
			var val = value.substring(0, 7);
			return val.split('-').join('.')
		}
	}
	// 时间转换
	template.defaults.imports.dateFormat = function (date, format) {
		if (date == null || date == '') {
			return 'time'
		}
		var date = new Date(date);
		var year = date.getFullYear(); // 年
		var month = date.getMonth() + 1; // 月
		month = month < 10 ? '0' + month : month;
		var day = date.getDate(); // 日
		day = day < 10 ? '0' + day : day;
		var hours = date.getHours(); // 时
		hours = hours < 10 ? '0' + hours : hours;
		var minutes = date.getMinutes() // 分
		minutes = minutes < 10 ? '0' + minutes : minutes;
		var seconds = date.getSeconds() // 秒
		seconds = seconds < 10 ? '0' + seconds : seconds;

		switch (format) {
			case 'M-D':
				return (month + '月' + day + '日');
				break;
			case 'Y-M-D':
				return (year + '-' + month + '-' + day);
				break;
			default:
				return (year + '-' + month + '-' + day + " " + hours + ':' + minutes + ':' + seconds);
				break;
		}
	};
	// 时间mini格式化
	template.defaults.imports.miniFormat = function (times) {
		var nowDate = new Date(); // 获取现在的时间
		var time = nowDate.getTime(); // 获取现在的毫秒数
		var oldDate = new Date(times);
		var year = oldDate.getFullYear();
		var month = oldDate.getMonth() + 1;
		var day = oldDate.getDate();
		var date = time - times;
		var H = Math.floor(date / (1000 * 60 * 60));
		var D = Math.floor(date / (1000 * 24 * 60 * 60));
		var M = Math.floor(date / (1000 * 60));
		if (times == '' || times == null) {
			return 'time'
		}
		if (date <= 1000 * 60) {
			return '刚刚'
		} else if (date > (1000 * 60) && date <= 1000 * 3600) {
			return M + '分钟前'
		} else if (date > (1000 * 60 * 60) && date <= 1000 * 86400) {
			return H + '小时前'
		} else if (date > (1000 * 24 * 60 * 60) && date <= (1000 * 2 * 24 * 60 * 60)) {
			if (oldDate.getDate() + 1 == nowDate.getDate()) {
				return '昨天'
			} else {
				return '前天'
			}
			// 只显示七天
		} else if (date > (1000 * 24 * 60 * 60) && date < 1000 * 86400 * 7) {
			return D + '天前'
		} else {
			return year + '-' + month + '-' + day
		}
	}
})